package controllers

import (
	"CRMSystem/models"
	"CRMSystem/utils"
)

type RegisterController struct {
	MainController
}

// Register 注册
func (c *RegisterController) Register() {
	username := c.GetString("username")
	password := utils.SHA256(c.GetString("password"))
	phoneNumber := c.GetString("phoneNumber")
	user := models.RegisterModel{
		UserName:    username,
		Password:    password,
		PhoneNumber: phoneNumber,
	}

	err := models.Register(user)
	if err == nil {
		c.Data["Status"] = "注册成功"
		c.TplName = "login.tpl"
	} else {
		c.Data["Status"] = "注册失败，你不是该公司员工，请联系后台管理员"
		c.TplName = "login.tpl"
	}
}
